<jsp:useBean id="database" class="controller.DatabaseController" scope="page" />
<%@page import="model.ManagementAssistent"%>
<%@page import="model.Training"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Training konfigurieren">
<meta name="author" content="ldonker">
<title>Training konfigurieren</title>
<!-- Bootstrap core CSS -->
<link href="dist/css/bootstrap.css" rel="stylesheet">
<link href="dist/css/site.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="dist/js/bootstrap.js"></script>
</head>


<body>
<%
	ManagementAssistent ma = new ManagementAssistent(1, "Test", "Admin", "Max");

	String firmenname1 = request.getParameter("firmenname");
	int firmenname = Integer.parseInt("" + firmenname1.charAt(0));
	String produktID1 = request.getParameter("produkt");
	int produktID = Integer.parseInt("" + produktID1.charAt(0));
	String anfangsdatum = request.getParameter("anfangsdatum");
	String enddatum = request.getParameter("enddatum");
	String tage1 = request.getParameter("tage");
	int tage = Integer.parseInt(tage1);
	String trainerID1 = request.getParameter("trainer");
	int trainerID = Integer.parseInt("" + trainerID1.charAt(0));
	String ortID1 = request.getParameter("ort");
	int ortID = Integer.parseInt("" + ortID1.charAt(0));
	String bemerkungen = request.getParameter("bemerkungen");
	
	Training trainingspeichern = new Training();
	
	//Managementassistent (Standard)
	trainingspeichern.setManagementassistent(ma);
	
	//Database Connect um Kunde, Ort, Produkt und Trainer zu bekommen
	database.connect();
	
	//Externe Orte speichern.
	trainingspeichern.setKunde(database.getKundeByID(firmenname));
	trainingspeichern.setOrt(database.getOrtByID(ortID));
	trainingspeichern.setProdukt(database.getProduktByID(produktID));
	trainingspeichern.setTrainer(database.getTrainerByID(trainerID));
	
	//Sonstige Felder
	trainingspeichern.setTage(tage);
	trainingspeichern.setAnfangsdatum(anfangsdatum);
	trainingspeichern.setEnddatum(enddatum);
	
	boolean erfolgreich = database.insertTraining(trainingspeichern);
	//Database Close
	database.close();
%>



	<div class="container">
		<div class="header">
			<ul class="nav nav-pills pull-right">
				<li class="active"><a href="index.jsp">Home</a></li>
			</ul>
			<h3 class="text-muted">PlEnTra</h3>
		</div>

		<div class="jumbotron">
			<h1>Training konfigurieren</h1>
		</div>

		<div class="row marketing">
			<%
			if(erfolgreich){
				out.println("<div class='alert alert-success'>Speichern des Trainings erfolgreich</div>");
			}else{
				out.println("<div class='alert alert-danger'>Speichern des Trainings nicht erfolgreich</div>");
			}
			%>
		<a href="index.jsp"><button type="button" class="btn btn-primary">Weiter...</button></a>
		</div>

		<div class="footer">
			<p>&copy;CSC/PBSY PlEnTra 2013</p>
		</div>

	</div>
	<!-- /container -->
</body>
</html>
